package com.wxq.workpad.lailiao.adapter

import android.content.Context
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.ImageView
import android.widget.TextView
import androidx.recyclerview.widget.RecyclerView
import com.bumptech.glide.Glide
import com.wxq.workpad.R
import com.wxq.workpad.entity.LaiLiaoItemEntity
import com.wxq.workpad.finishproduct.ProductTestDetailActivity

/**
 * @Description: 类作用描述
 */
class LaiLiaoListAdapter(context: Context):RecyclerView.Adapter<RecyclerView.ViewHolder>() {
    private var mContext:Context

    private var mData:MutableList<LaiLiaoItemEntity>

    private lateinit var listener:(position:Int)->Unit

    init {
        mContext=context
        mData= mutableListOf()
    }

    override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): RecyclerView.ViewHolder {
        return ItemHold(LayoutInflater.from(mContext).inflate(R.layout.item_lailiao,parent,false))
    }

    override fun getItemCount(): Int {
        if (mData==null){
            return 0;
        }
        return mData.size
    }

    fun updateDate(data:MutableList<LaiLiaoItemEntity>){
         mData=data
        notifyDataSetChanged()
    }

    override fun onBindViewHolder(holder: RecyclerView.ViewHolder, position: Int) {
        if (holder is ItemHold){
            val item = mData.get(position)
            holder.asnNo.setText(item.asnNo)
            holder.supplierName.setText(item.supplierName)
            holder.materialCode.setText(item.materialCode)
            holder.materialName.setText(item.materialName)
            holder.specification.setText(item.specification)
            holder.manufacturer.setText(item.manufacturer)
            holder.tuhao.setText(item.tuhao)
            holder.billSource.setText(item.billSource)
            holder.billDate.setText(item.billDate)
            holder.purchaserName.setText(item.purchaserName)
            holder.purchaseType.setText(item.purchaseType)
            holder.mainQty.setText(item.mainQty.toString())
            holder.regionName.setText(item.regionName)
            holder.billNo.setText(item.billNo)

            if (item.status.equals("0")) {
                Glide.with(mContext).load(R.mipmap.daijianyan).into(holder.iv_state)
                holder.tv_test.visibility=View.VISIBLE
            }else{
                Glide.with(mContext).load(R.mipmap.jianyanhege).into(holder.iv_state)
                holder.tv_test.visibility=View.GONE
            }

             holder.tv_test.setOnClickListener {
                 ProductTestDetailActivity.naveToActivity(mContext,"ces")
             }


        }
    }

    fun setClickListener(itemClick:(position:Int)->Unit){
        listener=itemClick
    }

    inner class ItemHold(itemView: View) : RecyclerView.ViewHolder(itemView) {

       var asnNo:TextView
       var tv_test:TextView
       var iv_state:ImageView
       var supplierName:TextView
       var materialCode:TextView
       var materialName:TextView
       var specification:TextView
       var manufacturer:TextView
       var tuhao:TextView
       var billSource:TextView
       var billDate:TextView
       var purchaserName:TextView
       var purchaseType:TextView
       var mainQty:TextView
       var regionName:TextView
       var billNo:TextView

        init {
            asnNo=itemView.findViewById(R.id.asnNo)
            tv_test=itemView.findViewById(R.id.tv_test)
            iv_state=itemView.findViewById(R.id.iv_state)
            purchaseType=itemView.findViewById(R.id.purchaseType)
            materialName=itemView.findViewById(R.id.materialName)
            supplierName=itemView.findViewById(R.id.supplierName)
            materialCode=itemView.findViewById(R.id.materialCode)
            specification=itemView.findViewById(R.id.specification)
            manufacturer=itemView.findViewById(R.id.manufacturer)
            tuhao=itemView.findViewById(R.id.tuhao)
            billSource=itemView.findViewById(R.id.billSource)
            billDate=itemView.findViewById(R.id.billDate)
            purchaserName=itemView.findViewById(R.id.purchaserName)
            regionName=itemView.findViewById(R.id.regionName)
            billNo=itemView.findViewById(R.id.billNo)
            mainQty=itemView.findViewById(R.id.mainQty)


        }
    }
}